﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Castle.Windsor;
using Mammoth.Libs;

namespace Mammoth.Services
{
    public interface IViewModelFactory
    {
        Libs.WPFViewModelBase GetViewModel(Type type, IInputElement dispatcher);
        T GetViewModel<T>(IInputElement dispatcher) where T : WPFViewModelBase;
    }

    public class ViewModelFactory : IViewModelFactory
    {
        private IWindsorContainer container;

        public ViewModelFactory(IWindsorContainer container)
        {
            this.container = container;
        }

        public WPFViewModelBase GetViewModel(Type type, IInputElement dispatcher)
        {
            return (WPFViewModelBase)container.Resolve(type, new {dispatcher = dispatcher});
        }

        public T GetViewModel<T>(IInputElement dispatcher) where T : WPFViewModelBase
        {
            return (T)GetViewModel(typeof(T), dispatcher);
        }
    }
}
